public class Test05 {
    //自定义异常类
    class userNameException extends Exception{

    }

    class passWordException extends Exception{

    }
    //模拟实现一个登录的过程
    class  Login{
        private String username = "admin";
        private String password = "123456";
        //构造方法
        public void login(String username,String password) throws userNameException, passWordException {
            //事前访问型
            if (!username.equals(this.username)) {
//                System.out.println("用户名错误！");
                throw new userNameException();
            }
            if (!password.equals(this.password)) {
//                System.out.println("密码输入错误！");
                throw new passWordException();
            }
            System.out.println("登录成功！");
        }
    }
    public static void main(String[] args) {
        Login login = new Login();
        try {
            login.login("admin","123")
        } catch (userNameException e) {
            System.out.println("用户名错误！");
        } catch(passWordException e) {
            System.out.println("密码输入错误！");
        }

    }
}
